﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.ServiceModel;
using System.Text;
using WCFMINERP.BLL.OrderBll;
using WCFMINERP.BLL.ShopBLL;
using WCFMINERP.Contracts.DataContracts;
using WCFMINERP.Contracts.InterFaces;
using WCFMINERP.MODEL;

using System.Net;
using System.Net.Cache;

namespace WCFMINERP.Services.TransferFileServers
{
    //[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]

    public class ProductServer : IProductServer
    {
        ShopProductBll shopproductBll = new ShopProductBll();
        
        /// <summary>
        /// 获取所有产品数据
        /// </summary>
        /// <returns></returns>
        public List<ShopModels> GetProduct()
        {
            return  shopproductBll.GetShopList();
        }

        System.Web.Caching.Cache CacheData = System.Web.HttpRuntime.Cache;

        /// <summary>
        /// 根据ShopID 获取所有产品数据
        /// </summary>
        /// <returns></returns>
        public List<ShopModels> GetProducts(string shopid)
        {
            if (string.IsNullOrEmpty(shopid))
            {
                return null; //"请传入有效商户ID";
            }
            int a = 0;
            if (int.TryParse(shopid, out a) == false) //判断是否可以转换为整型
            {
                return null; //"商户ID为数字";
            }

            if (CacheData != null && CacheData.Count>0)
            {
                if (CacheData["Shop"] == null)
                {
                    List<ShopModels> list = shopproductBll.GetShopList(Convert.ToInt32(shopid));
                    CacheData.Insert("Shop", list);
                }

                List<ShopModels> data= CacheData.Get("Shop") as List<ShopModels>;

                return data;
            }
            return null;
        }

        /// <summary>
        /// 获取所有的paperFace且状态为1的
        /// </summary>
        /// <returns></returns>
        public List<PaperFaceModels> GetPaperFace()
        {
            return shopproductBll.GetPaperFace();
        }

        /// <summary>
        /// 获取配置文件的shopid信息
        /// </summary>
        /// <returns></returns>
        public List<ShopModels> GetPrdouctshop()
        {
           // return shopproductBll.GetShopList();

            int shopid = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["shopId"]);

            if (CacheData != null)
            {
                if (CacheData["defultShop"] == null)
                {
                    List<ShopModels> list = shopproductBll.GetShopList(Convert.ToInt32(shopid));
                    CacheData.Insert("defultShop", list);
                }
                List<ShopModels> data = CacheData.Get("defultShop") as List<ShopModels>;
                return data;
            }
            return null;

        }

        /// <summary>
        /// 添加关系
        /// </summary>
        /// <returns></returns>
        public int AddPrdouctRelationship(string clientid, string serverid)
        {
            return 0;//shopproductBll.GetShopList(Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["shopId"]));
        }
    }
}
